package com.atguigu.gmall.common.config.minio.config;

import com.atguigu.gmall.common.config.minio.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MinIoConfiguration {

    @Bean
    public MinioClient minioClient(MinioProperties minioProperties) throws Exception {
        MinioClient minioClient = new MinioClient(minioProperties.getEndpoint(), minioProperties.getAccessKey(), minioProperties.getSecretKey());
        // 检查存储桶是否已经存在
        boolean isExist = minioClient.bucketExists(minioProperties.getBucket());

        if (!isExist){
            minioClient.makeBucket(minioProperties.getBucket());
        }
        return minioClient;
    }
}
